package com.skeeey.aim.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;
import java.util.regex.Pattern;

import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.skeeey.aim.model.AutoRecord;
import com.skeeey.aim.model.AutoStatus;
import com.skeeey.aim.model.Dealer;

public class AIMUtil {
	private AIMUtil() {}
	
	public static<E> String toJSONArrayStr(List<E> list) {
		String jsonArrayStr = "{\"Rows\":[], \"Total\":0}";
		try {
			JSONArray jsonArray = new JSONArray();
			for(int i = 0; i < list.size(); i++) {
				JSONObject jsonObject = new JSONObject(list.get(i));
				jsonObject.put("__status", "null");
				jsonArray.put(i, jsonObject);
			}
			
			JSONObject rows = new JSONObject();
			rows.put("Rows", jsonArray);
			rows.put("Total", list.size());
			jsonArrayStr = rows.toString();
		} catch (JSONException e) {
			Logger.getLogger(AIMUtil.class).error("Transfer a list to json error!", e);
		}
		return jsonArrayStr;
	}
	
	@SuppressWarnings("rawtypes")
	public static AutoRecord toAutoRecordBy(String josnStr) {
		AutoRecord record = null;
		try {
			record = new AutoRecord();
			JSONObject jsonObject = new JSONObject(josnStr);
			Iterator it = jsonObject.keys();
			while(it.hasNext()) {
				String key = (String) it.next();
				Method setMethod = null; 
				for(Method method : AutoRecord.class.getMethods()) {
					String methodName = method.getName();
					if(methodName.startsWith("set")) {
						String fieldName = methodName.substring(3);
						if(fieldName.equalsIgnoreCase(key)) {
							setMethod = method;
							break;
						}
					}
				}
				
				if(setMethod != null) {
					Object val = jsonObject.get(key);
					if(!JSONObject.NULL.equals(val)) {
						if("status".equals(key)) {
							val = Integer.valueOf((String)val);
						} else if("timeStamp".equals(key)) {
							val = (Long) val;
						} else {
							val = (String) val;
						}
					} else {
						val = null;
					}
					
					setMethod.invoke(record, val);
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		
		return record;
	}
	
	public static boolean isValidSheetName(String sheetName) {
		return "在库".equals(sheetName) || "未提".equals(sheetName) || "虚拟".equals(sheetName) || "在途".equals(sheetName);
	}
	
	public static boolean isValidStatisticFile(File statisticFile) {
		boolean r = false;
		InputStream in = null;
		try {
			in = new FileInputStream(statisticFile);
			Workbook workbook = new HSSFWorkbook(in);
			int sheetNum = workbook.getNumberOfSheets();
			if(sheetNum == 11) {
				r = true;
			}
		} catch(Exception e) {
		} finally {
			if(in != null) {
				try {
					in.close();
				} catch (IOException e) {
					//do nothing
				}
			}
		}
		return r;
	}
	
	public static List<AutoRecord> getAutoRecordFrom(File originalFile, String suffix, String timeStamp, String dealerCode, long createTime) throws Exception {
		List<AutoRecord> records = new ArrayList<AutoRecord>();
		InputStream in = null;
		try {
			in = new FileInputStream(originalFile);
			Workbook workbook = null;
			if("xlsx".equals(suffix)) {
				workbook = new XSSFWorkbook(in);
			} else {
				workbook = new HSSFWorkbook(in);
			}
			int numberOfSheets = workbook.getNumberOfSheets();
			if(numberOfSheets == 4) {
				for(int si = 0; si < numberOfSheets; si++) {
					Sheet sheet = workbook.getSheetAt(si);
					String sheetName = sheet.getSheetName();
					if(isValidSheetName(sheetName.trim())) {
						PosUtil posUtil = new PosUtil(sheet.getRow(0));
						for(int ri= 1; ri < sheet.getLastRowNum() + 1; ri++) {
							Row row = sheet.getRow(ri);
							if(row != null) {
								AutoRecord autoRecord = new AutoRecord();
								autoRecord.setTimeStamp(timeStamp);
								autoRecord.setDealerCode(dealerCode);
								autoRecord.setCreateTime(createTime);
								String vinCode = null;
								if(!sheetName.equals("虚拟")) {
									int index = -1;
									if((index = posUtil.getVINCodeIndex()) != -1)
										vinCode = trimVINCode(getValueFrom(row.getCell(index)));
									if(vinCode != null && vinCode.length() > 0) {
										if((index = posUtil.getCustomerCodeIndex()) != -1)
											autoRecord.setCustomerCode(getValueFrom(row.getCell(index)));
										if((index = posUtil.getCustomerNameIndex()) != -1)
											autoRecord.setCustomerName(getValueFrom(row.getCell(index)));
										if((index = posUtil.getOriginalOrderNumberIndex()) != -1)
											autoRecord.setOriginalOrderNumber(getValueFrom(row.getCell(index)));
										if((index = posUtil.getOrderStartDateIndex()) != -1)
											autoRecord.setOrderStartDate(getValueFrom(row.getCell(index)));
										if((index = posUtil.getInStorageDateIndex()) != -1)
											autoRecord.setInStorageDate(getValueFrom(row.getCell(index)));
										if((index = posUtil.getOutStorageDateIndex()) != -1)
											autoRecord.setOutStorageDate(getValueFrom(row.getCell(index)));
										autoRecord.setVINCode(vinCode);
										if((index = posUtil.getEnginCodeIndex()) != -1)
											autoRecord.setEnginCode(getValueFrom(row.getCell(index)));
										if((index = posUtil.getAutoCodeIndex()) != -1)
											autoRecord.setAutoCode(getValueFrom(row.getCell(index)));
										if((index = posUtil.getAutoNameIndex()) != -1)
											autoRecord.setAutoName(getValueFrom(row.getCell(index)));
										if((index = posUtil.getColorNumberIndex()) != -1)
											autoRecord.setColorNumber(getValueFrom(row.getCell(index)));
										if((index = posUtil.getColorNameIndex()) != -1)
											autoRecord.setColorName(getValueFrom(row.getCell(index)));
										if((index = posUtil.getAutoAgeIndex()) != -1)
											autoRecord.setAutoAge(getValueFrom(row.getCell(index)));
										if((index = posUtil.getVersionIndex()) != -1)
											autoRecord.setVersion(getValueFrom(row.getCell(index)));
										if((index = posUtil.getInnerOrnamentIndex()) != -1)
											autoRecord.setInnerOrnament(getValueFrom(row.getCell(index)));
										if((index = posUtil.getInnerOrnamentNameIndex()) != -1)
											autoRecord.setInnerOrnamentName(getValueFrom(row.getCell(index)));
										if((index = posUtil.getOptionalPackageNameIndex()) != -1)
											autoRecord.setOptionalPackageName(getValueFrom(row.getCell(index)));
										if((index = posUtil.getStatusIndex()) != -1)
											autoRecord.setStatus(AutoStatus.getAutoStatusBy(getValueFrom(row.getCell(index))).getVal());
										if((index = posUtil.getAttributeNameIndex()) != -1)
											autoRecord.setAttributeName(getValueFrom(row.getCell(index)));
										if((index = posUtil.getFlagIndex()) != -1)
											autoRecord.setFlag(getValueFrom(row.getCell(index)));
										if((index = posUtil.getStorageLocationCodeIndex()) != -1)
											autoRecord.setStorageLocationCode(getValueFrom(row.getCell(index)));
										if((index = posUtil.getStorageLocationIndex()) != -1)
											autoRecord.setStorageLocation(getValueFrom(row.getCell(index)));
									}
								} else {
									int i = 0;
									String index0Val = getValueFrom(row.getCell(0));
									if(!"修改".equals(index0Val)) {
										String tryVal =  getValueFrom(row.getCell(1));
										if("修改".equals(tryVal)) {
											i = 1;
										}
									} 
									int vinCodeIndex = posUtil.getVINCodeIndex();
									if(vinCodeIndex != -1) {
										vinCode = trimVINCode(getValueFrom(row.getCell(vinCodeIndex)));
									}
									if(vinCode != null && vinCode.length() > 0) {
										autoRecord.setStatus(AutoStatus.getAutoStatusBy("虚拟").getVal());
										autoRecord.setModified("修改");
										autoRecord.setRetailOrder(getValueFrom(row.getCell(i + 1)));
										//retail time is also the order start time.
										//retail time is "2011/12/31-12:49:27"
										//order start time format is "yyyyMMdd"
										String retailTime = getValueFrom(row.getCell(i + 2));
										if(retailTime != null && retailTime.length() != 0) {
											autoRecord.setRetailTime(retailTime);
											String[] retailTimes = retailTime.split("-");
											autoRecord.setOrderStartDate(retailTimes[0].replaceAll("/", ""));
										}
										int index = posUtil.getAutoCodeIndex();
										if(index != -1)
											autoRecord.setAutoCode(getValueFrom(row.getCell(index)));
										if((index = posUtil.getColorNameIndex()) != -1)
											autoRecord.setColorName(getValueFrom(row.getCell(index)));
										if((index = posUtil.getAutoAgeIndex()) != -1)
											autoRecord.setAutoAge(getValueFrom(row.getCell(index)));
										if((index = posUtil.getVersionIndex()) != -1)
											autoRecord.setVersion(getValueFrom(row.getCell(index)));
										if((index = posUtil.getInnerOrnamentNameIndex()) != -1)
											autoRecord.setInnerOrnamentName(getValueFrom(row.getCell(index)));
										if((index = posUtil.getOptionalPackageNameIndex()) != -1)
											autoRecord.setOptionalPackageName(getValueFrom(row.getCell(index)));
										if((index = posUtil.getCustomerNameIndex()) != -1)
											autoRecord.setCustomerName(getValueFrom(row.getCell(index)));
										autoRecord.setRetailPrice(getValueFrom(row.getCell(vinCodeIndex - 1)));
										autoRecord.setVINCode(vinCode);
										autoRecord.setReselled(getValueFrom(row.getCell(vinCodeIndex + 1)));
										autoRecord.setIsAssembled(getValueFrom(row.getCell(vinCodeIndex + 2)));
									}
								}
								if(vinCode != null && vinCode.length() > 0) {
									records.add(autoRecord);
								}
							}
						}
					}
				}
			} 
		} catch (FileNotFoundException e) {
			throw new Exception("parse original file failed!!", e);
		} catch (IOException e) {
			throw new Exception("parse original file failed!!", e);
		} finally {
			if(in != null) {
				try {
					in.close();
				} catch (IOException e) {
					// do nothing
				}
			}
		}
		return records;
	}
	
	private static String trimVINCode(String vinCode) throws UnsupportedEncodingException {
		if(vinCode != null && vinCode.length() > 0) {
			String utf8_vinCode = URLEncoder.encode(vinCode, "UTF-8");
			if(!vinCode.equals(utf8_vinCode)) {
				vinCode = utf8_vinCode.replaceAll("%C2%A0", "");
			}
		}
		return vinCode;
	}
	
	public static List<Dealer> getDealersFrom(File dealerFile) {
		List<Dealer> dealers = new ArrayList<Dealer>();
		InputStream in = null;
		try {
			in = new FileInputStream(dealerFile);
			Workbook workbook = new HSSFWorkbook(in);
			int numberOfSheets = workbook.getNumberOfSheets();
			if(numberOfSheets == 1) {
				Sheet sheet = workbook.getSheetAt(0);
				for(int ri = 1; ri < sheet.getLastRowNum() + 1; ri++) {
					Row row = sheet.getRow(ri);
					Dealer dealer = new Dealer();
					dealer.setNetCode(getValueFrom(row.getCell(0)));
					dealer.setRssc(getValueFrom(row.getCell(1)));
					dealer.setProvince(getValueFrom( row.getCell(2)));
					dealer.setCity(getValueFrom(row.getCell(3)));
					dealer.setName(getValueFrom(row.getCell(4)));
					dealer.setShortName(getValueFrom( row.getCell(5)));
					dealers.add(dealer);
				}
			}
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			if(in != null) {
				try {
					in.close();
				} catch (IOException e) {
					// do nothing
				}
			}
		}
		return dealers;
	}
	
	public static String getValueFrom(Cell cell) throws UnsupportedEncodingException {
		String val = null;
		if(cell != null) {
			int cellType = cell.getCellType();
			switch (cellType) {
			case Cell.CELL_TYPE_NUMERIC:
				if (HSSFDateUtil.isCellDateFormatted(cell)) {
					val = String.valueOf(cell.getDateCellValue().getTime());
				} else {
					val = String.valueOf((int) cell.getNumericCellValue());
				}
				break;
			case Cell.CELL_TYPE_STRING:
				val = cell.getStringCellValue();
				if(val != null) {
					val = val.trim();
				}
				break;
			case Cell.CELL_TYPE_FORMULA:
				val = cell.getCellFormula();
				if(val != null) {
					val = val.trim().replaceAll("\"", "");
				}
				break;
			case Cell.CELL_TYPE_BLANK:
				break;
			case Cell.CELL_TYPE_BOOLEAN:
				val = String.valueOf(cell.getBooleanCellValue());
				break;
			case Cell.CELL_TYPE_ERROR:
				break;
			default:
				break;
			}
		}
		return val;
	}
	
	public static String getMD5(String strSrc) {
		MessageDigest md = null;
		String strDes = null;
		if(strSrc != null) {
			byte[] bt = strSrc.getBytes();
			try {
				md = MessageDigest.getInstance("MD5");
				md.update(bt);
				byte[] bts = md.digest();			
				String des = "";
				String tmp = null;
				for (int i = 0; i < bts.length; i++) {
					tmp = (Integer.toHexString(bts[i] & 0xFF));
					if (tmp.length() == 1) {
						des += "0";
					}
					des += tmp;
				}
				strDes = des;
			} catch (NoSuchAlgorithmException e) {
				e.printStackTrace();
			}
		}
		return strDes;
	}
	
	public static File saveVINFileToTemp(String vinImageName, File vinImage) throws Exception {
		if(vinImageName == null || vinImageName.length() == 0) {
			throw new IllegalArgumentException("The image name is empty");
		}
		
		if(vinImage == null) {
			throw new IllegalArgumentException("The image is null");
		}
		
		String tempPathName = getSystemConfig("vin.image.temp.path");
		File tempPath = new File(tempPathName);
		File tempImageFile = null;
		if(tempPath.exists() && tempPath.isDirectory()) {
			tempImageFile = new File(tempPathName + vinImageName);
			vinImage.renameTo(tempImageFile);
		} else {
			throw new IllegalArgumentException("Temp path config error, temp path:[" + tempPath + "]");
		}
		
		return tempImageFile;
	}
	
	public static String getVINCodeBy(String vinImageName) throws Exception {
		if(vinImageName == null || vinImageName.length() == 0) {
			throw new IllegalArgumentException("The image name is empty");
		}
		
		return vinImageName.substring(0, vinImageName.indexOf("."));
	}
	
	public static String getSystemConfig(String key) {
		String val = null;
		ResourceBundle rb = ResourceBundle.getBundle("systemConf");
		val = (String) rb.getObject(key);
		return val;
	}
	
	public static String findDataStoragePathStrBy(Dealer dealer, String dateStr) {
		String subPathStr = dealer.getRssc() + File.separator + dealer.getProvince() + File.separator + dealer.getCity() + File.separator + dealer.getShortName();
		String dataStoragePathStr = getSystemConfig("data.storage.path") + File.separator + subPathStr + File.separator + dateStr;
		return dataStoragePathStr;
	}
	
	public static void createDataStorageDirBy(List<Dealer> dealers) throws Exception {
		String rootPathStr = getSystemConfig("data.storage.path");
		for(Dealer dealer : dealers) {
			String subPathStr = dealer.getRssc() + File.separator + dealer.getProvince() + File.separator + dealer.getCity() + File.separator + dealer.getShortName();
			String dataStoragePathStr = rootPathStr + File.separator + subPathStr;
			File dataStoragePath =  new File(dataStoragePathStr);
			if(!dataStoragePath.exists()) {
				if(!dataStoragePath.mkdirs()) {
					throw new IllegalArgumentException("Can not create root path:[" + rootPathStr + "]");
				}
			}
		}
	}
	
	public static void saveVINImage(AutoRecord record, String destPathStr, Dealer dealer, String imageName, File image, String imgType, String fsName) throws Exception {
		// 系统外
		if(record == null) {
			destPathStr = destPathStr + File.separator + "系统外";
		} else {
			if("omd".equals(imgType)) {
				destPathStr = destPathStr + File.separator + "状态二";
			} else {
				switch (record.getStatus()) {
				// 在途已到达 (在途)
				case 0:
					destPathStr = destPathStr + File.separator + "在途已到达";
					break;
				// 状态一 (在库)
				case 1:
					destPathStr = destPathStr + File.separator + "状态一" + File.separator + fsName;
					break;
				// 状态三 (虚拟)
				case 3:
					destPathStr = destPathStr + File.separator + "状态三" + File.separator + fsName;
					break;
				default:
					destPathStr = null;
					break;
				}
			}
		}
		if(destPathStr != null) {
			String destFileStr = destPathStr + File.separator + "上海大众-" + dealer.getNetCode() + "-" + dealer.getShortName() + "-" + imageName;
			FileUtils.copyFile(image, new File(destFileStr));
		}
	}
	
	public static String getDirName(String destPathStr, int type, String sName) {
		String name = null;
		switch (type) {
		case 0:
			name = destPathStr + File.separator + "状态一" + File.separator + sName;
			break;
		case 1:
			name = destPathStr + File.separator + "状态二";
			break;
		case 2:
			name = destPathStr + File.separator + "状态三" + File.separator + sName;
			break;
		case 3:
			name = destPathStr + File.separator + "在途已到达";
			break;
		case 4:
			name = destPathStr + File.separator + "系统外";
			break;
		case 5:
			name = destPathStr + File.separator + "证明材料";
			break;
		}
		return name;
	}
	
	public static void saveProvedFile(File provedFile, String destPathStr, int provedType, String provedFileName) throws IOException {
		switch (provedType) {
		case 1:
			destPathStr = destPathStr + File.separator + "证明材料" + File.separator + "系统外";
			break;
		case 2:
			destPathStr = destPathStr + File.separator + "证明材料" + File.separator + "虚拟未查到";
			break;
		case 3:
			destPathStr = destPathStr + File.separator + "证明材料" + File.separator + "状态二";
			break;
		}
		if(destPathStr != null) {
			String destFileStr = destPathStr + File.separator + provedFileName;
			FileUtils.copyFile(provedFile, new File(destFileStr));
		}
	}
	
	public static List<String> getSubDirs(File rootPath) {
		List<String> dirs = new ArrayList<String>();
		for(File subDir : rootPath.listFiles()) {
			if(subDir.isDirectory()) {
				dirs.add(subDir.getName());
			}
		}
		return dirs;
	}
	
	public static List<String> getVINCodesBy(int status, String rootStoragePath) throws Exception {
		List<String> vinCodes = new ArrayList<String>();
		String path = rootStoragePath;
		switch (status) {
		case 0:
			path = path + File.separator + "状态一";
			break;
		case 1:
			path = path + File.separator + "状态二";
			break;
		case 2:
			path = path + File.separator + "状态三";
			break;
		case 3:
			path = path + File.separator + "系统外";
			break;
		case 5:
			path = path + File.separator + "在途已到达";
			break;
		default:
			break;
		}
		File storagePath =  new File(path);
		if(storagePath.exists()) {
			for(File file :storagePath.listFiles()) {
				if(file.isDirectory()) {
					for(File _file: file.listFiles()) {
						if(_file.isFile()) {
							String imageName = _file.getName().substring(_file.getName().indexOf(".") - 6);
							vinCodes.add(getVINCodeBy(imageName));
						}
					}
				}
				if(file.isFile()) {
					String imageName = file.getName().substring(file.getName().indexOf(".") - 6);
					vinCodes.add(getVINCodeBy(imageName));
				}
			}
		}
		return vinCodes;
	}
	
	public static String getSecondaryNameBy(int status, String rootStoragePath, String vinCode) throws Exception {
		String secondaryName = null;
		String path = rootStoragePath;
		switch (status) {
		case 0:
			path = path + File.separator + "状态一";
			break;
		case 2:
			path = path + File.separator + "状态三";
			break;
		}
		File storagePath =  new File(path);
		if(storagePath.exists()) {
			for(File file :storagePath.listFiles()) {
				if(file.isDirectory() && !"本店".equals(file.getName())) {
					for(File _file: file.listFiles()) {
						if(_file.isFile()) {
							String imageName = _file.getName().substring(_file.getName().indexOf(".") - 6);
							if(vinCode.endsWith(getVINCodeBy(imageName))) {
								return file.getName();
							}
						}
					}
				}
			}
		}
		return secondaryName;
	}
	
	public static boolean isNumeric(String str){
	    Pattern pattern = Pattern.compile("[0-9]*");
	    return pattern.matcher(str).matches();   
	}
	
	public static String getQuarterByMonth(String month) {
		int m = Integer.parseInt(month);
		int q = 0;
		switch (m) {
		case 1:
		case 2:
		case 3:
			q = 1;
			break;
		case 4:
		case 5:
		case 6:
			q = 2;
			break;
		case 7:
		case 8:
		case 9:
			q = 3;
			break;
		case 10:
		case 11:
		case 12:
			q = 4;
			break;
		}
		return String.valueOf(q);
	}
	
	public static void main(String[] args) throws Exception {
		String d1 =  "20120302";
		//String d2 =  "2013-03-02";
		
		Date dd1 = new SimpleDateFormat("yyyyMMdd").parse(d1);
		
		Date dd2 = new Date();
		
		System.out.println(((dd2.getTime() - dd1.getTime())/ 24 / 3600000));
		
//		System.out.println(getVINCodeBy("123456.jpg"));
		
//		System.out.println(">" + "  a111  ".trim() + "<");
		
//		List<Dealer> dealers = getDealersFrom(new File("/mnt/auto_inventory_management/document/dealers/dealers.xls"));
//		System.out.println(dealers.size());
//		createDataStorageDirBy(dealers);
		
//		String jStr = "{\"outStorageDate\":\"0\",\"colorName\":\"平安白\",\"originalOrderNumber\":\"0B12372263\",\"timeStamp\":1359274861163,\"autoName\":\"桑塔纳NF1.4手动\",\"storageLocationCode\":\"aaaaaa二环东路86号\",\"VINCode\":\"LSVAA6BR2CN011991\",\"autoCode\":\"BR23C4\",\"storageLocation\":\"\",\"version\":\"0\"," +
//				"\"id\":\"ff8080813c7b12d9013c7b1863320175\",\"reselled\":null,\"retailPrice\":null,\"enginCode\":\"2248\",\"customerCode\":\"2050505\",\"retailTime\":null," +
//				"\"retailOrder\":null,\"inStorageDate\":\"20121209\",\"__status\":\"update\",\"customerName\":\"河北众诚汽车贸易有限公司\",\"status\":\"1\",\"autoAge\":\"2013\",\"innerOrnament\":\"JM\",\"optionalPackageName\":\"WS9WT1\",\"innerOrnamentName\":\"黑色\",\"orderStartDate\":\"20121205\",\"modified\":null,\"attributeName\":\"提单\",\"flag\":\"1\",\"colorNumber\":\"MZ\",\"isAssembled\":null,\"__id\":\"r1001\",\"__previd\":-1,\"__index\":0,\"__nextid\":\"r1002\"}";
//		AutoRecord r = toAutoRecordBy(jStr);
//		System.out.println(r.getId());
		
//		String tempPathName = getSystemConfig("vin.image.temp.path");
//		File tempPath = new File(tempPathName);
//		System.out.println(tempPath.isDirectory());
		
//		File file = new File("/mnt/auto_inventory_management/document/original-data/error.xls");
//		List<AutoRecord> list = getAutoRecordFrom(file, "xls", "2010-10-12", "", 0L);
//		System.out.println("total:" + list.size());
//		int s0 = 0;
//		int s1 = 0;
//		int s2 = 0;
//		int s3 = 0;
//		for(AutoRecord autoRecord : list) {
//			switch (autoRecord.getStatus()) {
//			case 0:
//				s0++;
//				break;
//			case 1:
//				s1++;
//				break;
//			case 2:
//				s2++;
//				break;
//			case 3:
//				s3++;
//				break;
//			default:
//				break;
//			}
//		}
//		System.out.println("在途->" + s0);
//		System.out.println("在库->" + s1);
//		System.out.println("未提->" + s2);
//		System.out.println("虚拟->" + s3);
		
		String test = "上海大众-2010301-乌海庞大-012270.JPG";
		System.out.println(test.indexOf("."));
		System.out.println(test.substring(test.indexOf(".") - 6));
	}
}
